package com.evil.kingdom.pojo.entity.action;

import com.evil.common.mongo.entity.SingleName;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

import java.io.Serial;
import java.io.Serializable;

/**
 * 导航本路径
 *
 * @author liyang
 * @date 2024-05-24 10:15
 */
@Getter
@Setter
public class ActionPosition implements SingleName, Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 地名
     */
    private String name;

    /**
     * 出发点
     */
    @Valid
    @NotNull(message = "导航本路径出发点不能为空")
    private AbstractPosition depart;

    /**
     * 目的点
     */
    @Valid
    @NotNull(message = "导航本路径目的点不能为空")
    private AbstractPosition dest;

    /**
     * 速度
     */
    private Double speed;

    public ActionPosition() {
        this.speed = 0d;
        this.name = "无名";
    }

    public ActionPosition(AbstractPosition depart, AbstractPosition dest) {
        this.depart = depart;
        this.dest = dest;
        this.speed = 0d;
        this.name = "无名";
    }

    public ActionPosition(AbstractPosition depart, AbstractPosition dest, Double speed) {
        this.depart = depart;
        this.dest = dest;
        this.speed = speed;
        this.name = "无名";
    }

    public ActionPosition reverse() {
        return new ActionPosition(this.dest, this.depart, this.speed);
    }

    public String printInfo() {
        return String.format("%s->%s", this.depart.toString(), this.dest.toString());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ActionPosition that = (ActionPosition) o;

        if (!depart.equals(that.depart)) return false;
        return dest.equals(that.dest);
    }

    @Override
    public int hashCode() {
        int result = depart.hashCode();
        result = 31 * result + dest.hashCode();
        return result;
    }

    @Override
    public String getEntityName() {
        return "导航本路径";
    }
}
